﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CCF20Model.ConfigurationFile
{
    public class ZICMonitorConnection : IConfiguration
    {
        private string zicMonitorConnectionTemplate = "metadata=res://*/CCF20Model.csdl|res://*/CCF20Model.ssdl|res://*/CCF20Model.msl;" +
                                               "provider=System.Data.SqlClient;provider connection string=\'MultipleActiveResultSets=True;" +
                                               "Data Source={0};Initial Catalog={1};User Id={2};Password={3}\';";

        private IConfiguration _previousConfig;
        private string strResult = string.Empty;

        public ZICMonitorConnection(IConfiguration previousConfig)
        {
            _previousConfig = previousConfig;
        }

        public string VerifyResult()
        {
            WiseLinkConfiguration myConfig = ConfiguraitonHelper.MyConfiguration;
            string myConfigConnection = string.Format(zicMonitorConnectionTemplate, myConfig.database, myConfig.catalog, myConfig.user, myConfig.password);

            string zicConnection = ConfiguraitonHelper.GetConfigValueFromAppConfig(AppConfigFileName.ZICMonitor, AppConfigFileNodeName.CCF20Entities);

            if (!zicConnection.Equals(myConfigConnection, StringComparison.OrdinalIgnoreCase))
            {
                ConfiguraitonHelper.SetConfigValueToAppConfig(AppConfigFileName.ZICMonitor, AppConfigFileNodeName.CCF20Entities, myConfigConnection);
                LoggerHelper.LogCCF20(string.Format("ZICMonitor  ConnectionString={0}", zicConnection));
                LoggerHelper.LogCCF20(string.Format("ZICTemplate ConnectionString={0}", myConfigConnection));
                strResult = "ZICMonitor AppConfig File CCF20Entities has different value than the configur.xml";
            }
         
            return string.Format("{0} \r\n{1}", _previousConfig.VerifyResult(), strResult);
        }

    }
}
